package com.zp.common.pdf;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

import java.util.*;

/**
 * 数据源
 */
public class HisReportDataSource implements JRDataSource {

    List dataList = new ArrayList();
    Map map = new HashMap();
    private Iterator iter;

    //以sex为参数的有参构造函数，用于数据初始化
    public HisReportDataSource (Map attris) {
        dataList.add(attris);
        //要将List中的数据迭代，需要使用Iterator迭代对象
        iter = dataList.iterator();
    }

    @Override
    public boolean next () throws JRException {
        if (iter.hasNext()) {
            map = (Map) iter.next();
            return true;
        }
        return false;

    }

    @Override
    public Object getFieldValue (JRField jrField) throws JRException {
        return map.get(jrField.getName());
    }
}
